package perf.data;

public class InlineCost extends BaseItem<Linecosts,Sourcefile> {

	private Sourcefile dest;
	
	public InlineCost( Function src, Sourcefile dest ) {
		super( composeName( src, dest ) );
		this.dest = dest;
	}
	
	public Sourcefile getDest() {
		return dest;
	}

	public void setDest(Sourcefile dest) {
		this.dest = dest;
	}

	public Linecosts getLinecostInstance( int line ) {
		Linecosts lc = findSibling( line + "" );
		
		if ( lc != null ) {
			return lc;
		} else {
			return add( new Linecosts( line ) );
		}
	}
	
	@Override
	public long getCost(int costidx) {
		long costs = 0;
		
		for ( Linecosts l : siblings() ) {
			costs += l.getCost(costidx);
		}
		return costs;
	}
	
	public static String composeName( Function src, Sourcefile dst ) {
		return src.getName() + "->" + dst.getName();
	}
}
